Ext.ns("Ext.ux.grid");
Ext.ux.grid.CustomerGridView = Ext.extend(Ext.grid.GridView,{
  flagName:{},
  gFlag:'',
  isNew:false,
  colorFlag:true,
  constructor: function(conf) {
        Ext.ux.grid.CustomerGridView.superclass.constructor.call(this, conf);
    },
    displayValue : function(colName,column, value, metaData, record, rowIndex, colIndex, store) {
	    	   //  return column.renderer(value, metaData, record, rowIndex, colIndex, store);
         
	    if(!this.isNeedRowSpan(colName)){
	     return column.renderer(value, metaData, record, rowIndex, colIndex, store);
		}
		//in columnNames
	    if(isNew){
	    	
	    	//alert(colName+'need rowspan');
	       return column.renderer(value, metaData, record, rowIndex, colIndex, store);
	    }else{
	    	return '';
		}
	 },
    doRender : function(cs, rs, ds, startRow, colCount, stripe){
	   var ts = this.templates,
		ct = ts.cell, 
		rt = ts.row, 
		last = colCount-1;
        var tstyle = 'width:'+this.getTotalWidth()+';';
        var buf = [], cb, c,p = {},rp = {tstyle: tstyle},r,fitWidth;
	 	var cmConfig = this.cm.config, 
		rowspans=[];
		for(var i = 0, len = cmConfig.length; i < len; i++){
            rowspans.push(Math.max((cmConfig[i].rowspan || 0), 0));
        }
        var flagName = 'none';
        for(var j = 0, len = rs.length; j < len; j++){
            r = rs[j];
			cb = [];
            var rowIndex = (j+startRow);//rowIndex 第几条记录
           
            var groupColumnValue = r.data[this.groupColumn];//第j条记录
            if(groupColumnValue!= this.gFlag){
             this.gFlag = groupColumnValue ;
             isNew = true;
             if(this.colorFlag){this.colorFlag=false;}else{this.colorFlag=true}
            }else{
             isNew = false ;
            }
            
           for(var i = 0; i < colCount; i++){
            	
                c = cs[i];
                p.id = c.id;//第i列的id
                p.css = i === 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');//为第一列和最后一列加样式
                p.attr = p.cellAttr = "";//cell属性
                p.value = this.displayValue(c.name,cmConfig[i], r.data[c.name], p, r, rowIndex, i, ds);//清楚rowspan一下的记录.保留第一条记录
			    p.style = c.style;
			    if(Ext.isEmpty(p.value)){
                    p.value = "&#160;";
                }
              
				//第i列是否dirty
                if(this.markDirty && r.dirty && typeof r.modified[c.name] !== 'undefined'){
                    p.css += ' x-grid3-dirty-cell';
                }
               if(this.isNeedRowSpan(c.name)){
               	if(isNew){
               		
                       
                   }
                }else{
                  
                }
				cb[cb.length] = ct.apply(p);
               
			}
			//end of 遍历各个列
            var alt = [];
            if(this.colorFlag == true){
            	 alt[0] = "x-grid3-row-mycolor";
            	//alt[0] = "x-grid3-row-alt";
            }else{
               
            }
            if(r.dirty){//判断是否dirty
                alt[1] = " x-grid3-dirty-row";
            }
            rp.cols = colCount;
            if(this.getRowClass){
                alt[2] = this.getRowClass(r, rowIndex, rp, ds);
            }
            rp.alt = alt.join(" ");
            rp.cells = cb.join("");
            buf[buf.length] =  rt.apply(rp);//吧rowproperty加入到RowTemple中
        }
        this.gFlag ='';
		//alert(buf.join(""));
		this.jack = buf.join("");
		
        return buf.join("");
    },
    isNeedRowSpan:function(colName){
       if(null==this.columnNames){return false;}
        for(var i=0;i<this.columnNames.length;i++){
             if(colName == this.columnNames[i]){
             	 return true;
             }
        }
        return false;
     },//{id1:'',id2:'',id3:'',id4:''}
     isFirst:function(colName,value){
     	for(var p in this.flagName){
     		 if(p == this.groupColumn){//户号
     		      if(this.flagName[p]!= value){
     		         this.flagName = {};
     		      }
     		 }
             if(colName == p&& this.flagName[p] == value){
                return false;
             }
        }
      //第一条记录
        this.flagName[colName] = value ;
        if(colName == this.groupColumn){
        	//记录group值
           this.gFlag = value ;
        }
        return true;
     }
});